package ZMJ;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class danci extends JFrame implements ActionListener {
	JButton tjdc, xiugai, shanchu, xiugai2, shuaxing;
	JTable example;
	JPanel p1, p2, p3, p4;
	JTable table;
	JScrollPane jsp;

	public danci() {
		super("单词浏览与添加");
		this.setLayout(null);

		tjdc = new JButton("单词添加");
		tjdc.addActionListener(this);
		xiugai = new JButton("英文修改");
		xiugai.addActionListener(this);
		xiugai2 = new JButton("中文修改");
		xiugai2.addActionListener(this);
		shanchu = new JButton("单词删除");
		shanchu.addActionListener(this);
		shuaxing = new JButton("单词刷新");
		shuaxing.addActionListener(this);
		p1 = new JPanel();

		p1.add(tjdc);
		p1.add(shanchu);
		p1.add(xiugai);
		p1.add(xiugai2);
		p1.add(shuaxing);

		jsp = new JScrollPane();
		table = new JTable() {

			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int row, int column) {
				return false; // 不可编辑
			}
		};
		table.setColumnSelectionAllowed(false);
		table.setRowSelectionAllowed(true);
		table.setDragEnabled(false);
		table.setRowHeight(25);
		String[] columns = { "编号", "英语单词", "汉语意思" }; // 创建列名数组.
		// 创建表格模型.
		DefaultTableModel model = new DefaultTableModel(columns, 0);
		table.setModel(model); // 设置表格模型.
		java.util.List<word> bases = WordUtil.getWordList();

		for (word base : bases) { // 遍历学生集合对象.
			String[] args = { String.valueOf(base.getWordid()),
					base.getEnglish(), base.getChinese() }; // 把学生信息拆分为数组,传递给args数组.
			model.addRow(args);
		}
		jsp.setViewportView(table);
		jsp.setSize(500, 200);

		p1.setBounds(0, 0, 500, 40);
		jsp.setBounds(0, 40, 496, 270);
		this.add(p1);
		this.add(jsp);
		this.setVisible(true);
		this.setSize(515, 360);

		// this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);// 对话框居中

	}

	// public static void main(String[] args) {
	// new danci();
	// }

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == tjdc) {
			dispose();
			new tianjia();
		}
		if (e.getSource() == shanchu) {
			new shanchu();
		}
		if (e.getSource() == xiugai) {
			new xiugai2();
		}
		if (e.getSource() == xiugai2) {
			new xiugai3();
		}
		if (e.getSource() == shuaxing) {
			dispose();
			new danci();
		}
	}
}
